package la.iok.hzsvn.lewin.movie.service;

import la.iok.hzsvn.lewin.movie.entity.BookChapter;
import la.iok.hzsvn.lewin.movie.entity.BookChapterInstance;
import la.iok.hzsvn.lewin.movie.mapper.BookChapterInstanceMapper;
import la.iok.hzsvn.lewin.mybatis.service.BaseServiceImpl;
import la.iok.hzsvn.share.annotations.NotNull;
import la.iok.hzsvn.share.annotations.NullElement;
import la.iok.hzsvn.share.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Collection;

@Service
public class BookChapterInstanceServiceImpl
        extends BaseServiceImpl<BookChapterInstance, BookChapterInstanceMapper,Long>
        implements BookChapterInstanceService{
    public BookChapterInstanceServiceImpl(BookChapterInstanceMapper mapper) {
        super(mapper);
    }

    @Override
    public Long save(@NotNull BookChapter book, @NotNull Long movieInstanceId) {
        BookChapterInstance instance = new BookChapterInstance();
        BeanUtils.copyProperties(book,instance);
        instance.setMovieInstanceId(movieInstanceId);
        instance.setId(null);
        instance.setChapterId(book.getId());
        insertSelective(instance);
        return instance.getId();
    }

    @Override
    public void markFileDeleted(@Nullable @NullElement Collection<Long> ids) {
        batchUpdate("fileDeleted",1, ids);
    }
}
